import VueRouter from 'vue-router'//引入router

import home from '../vue/home.vue'
import member from '../vue/member.vue'
import search from '../vue/search.vue'
import shopcar from '../vue/shopcar.vue'
import newsList from '../vue/news/newsList.vue'
import newsInfo from '../vue/news/newsInfo.vue'
import photo_list from '../vue/share_photo/photo_list.vue'
import photo_info from '../vue/share_photo/photo_info.vue'
import goodsList from '../vue/goods/goodsList.vue'
import goodsInfo from '../vue/goods/goodsInfo.vue'
import sku2 from '../vue/sku/sku.vue';
import test from '../vue/test.vue';

export var router=new VueRouter({
    // mode:'history',//用于去掉网址路径中的‘#’号
    //原地址:http://localhost:3002/#/home
    // 修改后地址：http://localhost:3002/home

    ///////////////////////////////////////////////////////////////////////////////////////
    routes:[
        {   path: '/', redirect: '/home' },
        {   path: '/home', component: home  },
        {   path: '/member', component: member },
        {   path: '/shopcar', component: shopcar , name:'shopcar'},
        {   path: '/search', component: search },
        {   path : '/home/newsList', component : newsList},
        {   path : '/home/newsInfo/:id', component : newsInfo},
        {   path : '/home/photo_list/:id', component : photo_list,
            meta:{title:'photo_list', keepAlive:true}  ,name :'photo_list'      
        },
        {   path : '/home/photoInfo/:id', component : photo_info},
        {   path : '/home/goodList', component : goodsList},
        {   path : '/home/goodsInfo/:id', component : goodsInfo},
        {   path : '/sku', component:sku2},
        {   path : '/test', component:test}
        
    ]
    ,

    linkActiveClass:'mui-active'
    // linkActiveClass:'van-tabbar-item--active'
                    


    ////////////////////////////////////////////////////////////////////////////////////////
    // bug起源：当上一个页面滚动到非头部时，点击下一个页面，滚动条会自动跳转到上一个页面的位置（就是非头部就是了）
    // 这段用于跳转路由时，修补跳转非头部的bug
    // scrollBehavior (to, from, savedPosition) {
    //     if (savedPosition) {
    //       return savedPosition
    //     } else {
    //       return { x: 0, y: 0 }
    //     }
    //   }
// 记录上次浏览位置，下次回来还是这个位置,但是出现了刷新页面出现get不到的现象

    // scrollBehavior (to, from, savedPosition) {
    //     if (savedPosition) {
    //       return savedPosition
    //     } else {
    //       if (from.meta.keepAlive) {
    //         from.meta.savedPosition = document.body.scrollTop
    //       }
    //       return { x: 0, y: to.meta.savedPosition || 0 }
    //     }
    //   }

})


